<?php

namespace App\Http\Controllers;
use App\Role;
use App\User;
use Illuminate\Http\Request;

class RoleController extends Controller {

	protected $model, $user;

	public function __construct(Role $role, User $user) {
		$this->user = $user;
		$this->model = $role;
	}

	public function roles(Request $request) {
		$user_id = $request->user_id ?: abort(404);
		$is_admin = $request->is_admin ?: 0;
		$user = $this->user->findOrCreate(['six_id' => $user_id, 'is_admin' => $is_admin]);
		if ($request->business) {
			$user->business()->sync($request->business);
		}
		echo json_encode(['code' => 1, 'msg' => 'success']);
	}
}
